package com.cenntro.auth.shiro;


import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.springframework.beans.factory.annotation.Autowired;

import com.cenntro.auth.mapper.SysSooidMapper;
import com.cenntro.auth.service.SysSooidService;
import com.cenntro.common.util.result.Result;
import com.google.common.collect.ImmutableMap;

/**
 * 输错5次密码锁定2分钟，ehcache.xml配置
 * @author 
 *
 */
public class RetryLimitHashedCredentialsMatcher extends HashedCredentialsMatcher {

	@Autowired
	private SysSooidService sysSooidService;

    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {

//		boolean matches = super.doCredentialsMatch(token, info);
		if(token instanceof UsernamePasswordToken){
			//根据用户的登陆信息创建一个token
			UsernamePasswordToken userToken = (UsernamePasswordToken) token;
			//String accountCredentials = (String) info.getCredentials();
//			User user = userService.findUserByUserName(userToken.getUsername());

			
			char[] passwordchars = userToken.getPassword();
			String password = new String(passwordchars);
			//验证令牌
			if(password.equals("")){
				return false;
			}else{
				Result result = sysSooidService.verify();
				if (Result.SUCCESS.equals(result.getState())){
					return true;
				}
			}
		}
		return false;
    }
}